/*
 * Bricks-OS, Operating System for Game Consoles
 * Copyright (C) 2008 Maximus32 <Maximus32@bricks-os.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307 USA
 */


#include "math.h"
#include "stdint.h"


#define MATH_TABLE_BITS (10) // 10bits == 1024 values
#define MATH_TABLE_SIZE (1<<MATH_TABLE_BITS)

const float angleToIndex = (float)(MATH_TABLE_SIZE >> 1) / M_PI;
#define ANGLE_TO_INDEX(a) ((unsigned int)((float)(a) * angleToIndex) & (MATH_TABLE_SIZE-1))


const float sinTable[MATH_TABLE_SIZE] =
{
  0.000000,
  0.006136,
  0.012272,
  0.018407,
  0.024541,
  0.030675,
  0.036807,
  0.042938,
  0.049068,
  0.055195,
  0.061321,
  0.067444,
  0.073565,
  0.079682,
  0.085797,
  0.091909,
  0.098017,
  0.104122,
  0.110222,
  0.116319,
  0.122411,
  0.128498,
  0.134581,
  0.140658,
  0.146730,
  0.152797,
  0.158858,
  0.164913,
  0.170962,
  0.177004,
  0.183040,
  0.189069,
  0.195090,
  0.201105,
  0.207111,
  0.213110,
  0.219101,
  0.225084,
  0.231058,
  0.237024,
  0.242980,
  0.248928,
  0.254866,
  0.260794,
  0.266713,
  0.272621,
  0.278520,
  0.284408,
  0.290285,
  0.296151,
  0.302006,
  0.307850,
  0.313682,
  0.319502,
  0.325310,
  0.331106,
  0.336890,
  0.342661,
  0.348419,
  0.354164,
  0.359895,
  0.365613,
  0.371317,
  0.377007,
  0.382683,
  0.388345,
  0.393992,
  0.399624,
  0.405241,
  0.410843,
  0.416430,
  0.422000,
  0.427555,
  0.433094,
  0.438616,
  0.444122,
  0.449611,
  0.455084,
  0.460539,
  0.465976,
  0.471397,
  0.476799,
  0.482184,
  0.487550,
  0.492898,
  0.498228,
  0.503538,
  0.508830,
  0.514103,
  0.519356,
  0.524590,
  0.529804,
  0.534998,
  0.540171,
  0.545325,
  0.550458,
  0.555570,
  0.560662,
  0.565732,
  0.570781,
  0.575808,
  0.580814,
  0.585798,
  0.590760,
  0.595699,
  0.600616,
  0.605511,
  0.610383,
  0.615232,
  0.620057,
  0.624859,
  0.629638,
  0.634393,
  0.639124,
  0.643832,
  0.648514,
  0.653173,
  0.657807,
  0.662416,
  0.667000,
  0.671559,
  0.676093,
  0.680601,
  0.685084,
  0.689541,
  0.693971,
  0.698376,
  0.702755,
  0.707107,
  0.711432,
  0.715731,
  0.720003,
  0.724247,
  0.728464,
  0.732654,
  0.736817,
  0.740951,
  0.745058,
  0.749136,
  0.753187,
  0.757209,
  0.761202,
  0.765167,
  0.769103,
  0.773010,
  0.776888,
  0.780737,
  0.784557,
  0.788346,
  0.792107,
  0.795837,
  0.799537,
  0.803208,
  0.806848,
  0.810457,
  0.814036,
  0.817585,
  0.821103,
  0.824589,
  0.828045,
  0.831470,
  0.834863,
  0.838225,
  0.841555,
  0.844854,
  0.848120,
  0.851355,
  0.854558,
  0.857729,
  0.860867,
  0.863973,
  0.867046,
  0.870087,
  0.873095,
  0.876070,
  0.879012,
  0.881921,
  0.884797,
  0.887640,
  0.890449,
  0.893224,
  0.895966,
  0.898674,
  0.901349,
  0.903989,
  0.906596,
  0.909168,
  0.911706,
  0.914210,
  0.916679,
  0.919114,
  0.921514,
  0.923880,
  0.926210,
  0.928506,
  0.930767,
  0.932993,
  0.935184,
  0.937339,
  0.939459,
  0.941544,
  0.943593,
  0.945607,
  0.947586,
  0.949528,
  0.951435,
  0.953306,
  0.955141,
  0.956940,
  0.958703,
  0.960431,
  0.962121,
  0.963776,
  0.965394,
  0.966976,
  0.968522,
  0.970031,
  0.971504,
  0.972940,
  0.974339,
  0.975702,
  0.977028,
  0.978317,
  0.979570,
  0.980785,
  0.981964,
  0.983105,
  0.984210,
  0.985278,
  0.986308,
  0.987301,
  0.988258,
  0.989177,
  0.990058,
  0.990903,
  0.991710,
  0.992480,
  0.993212,
  0.993907,
  0.994565,
  0.995185,
  0.995767,
  0.996313,
  0.996820,
  0.997290,
  0.997723,
  0.998118,
  0.998476,
  0.998795,
  0.999078,
  0.999322,
  0.999529,
  0.999699,
  0.999831,
  0.999925,
  0.999981,
  1.000000,
  0.999981,
  0.999925,
  0.999831,
  0.999699,
  0.999529,
  0.999322,
  0.999078,
  0.998795,
  0.998476,
  0.998118,
  0.997723,
  0.997290,
  0.996820,
  0.996313,
  0.995767,
  0.995185,
  0.994565,
  0.993907,
  0.993212,
  0.992480,
  0.991710,
  0.990903,
  0.990058,
  0.989177,
  0.988258,
  0.987301,
  0.986308,
  0.985278,
  0.984210,
  0.983105,
  0.981964,
  0.980785,
  0.979570,
  0.978317,
  0.977028,
  0.975702,
  0.974339,
  0.972940,
  0.971504,
  0.970031,
  0.968522,
  0.966976,
  0.965394,
  0.963776,
  0.962121,
  0.960431,
  0.958703,
  0.956940,
  0.955141,
  0.953306,
  0.951435,
  0.949528,
  0.947586,
  0.945607,
  0.943593,
  0.941544,
  0.939459,
  0.937339,
  0.935184,
  0.932993,
  0.930767,
  0.928506,
  0.926210,
  0.923880,
  0.921514,
  0.919114,
  0.916679,
  0.914210,
  0.911706,
  0.909168,
  0.906596,
  0.903989,
  0.901349,
  0.898674,
  0.895966,
  0.893224,
  0.890449,
  0.887640,
  0.884797,
  0.881921,
  0.879012,
  0.876070,
  0.873095,
  0.870087,
  0.867046,
  0.863973,
  0.860867,
  0.857729,
  0.854558,
  0.851355,
  0.848120,
  0.844854,
  0.841555,
  0.838225,
  0.834863,
  0.831470,
  0.828045,
  0.824589,
  0.821103,
  0.817585,
  0.814036,
  0.810457,
  0.806848,
  0.803208,
  0.799537,
  0.795837,
  0.792107,
  0.788346,
  0.784557,
  0.780737,
  0.776888,
  0.773010,
  0.769103,
  0.765167,
  0.761202,
  0.757209,
  0.753187,
  0.749136,
  0.745058,
  0.740951,
  0.736817,
  0.732654,
  0.728464,
  0.724247,
  0.720003,
  0.715731,
  0.711432,
  0.707107,
  0.702755,
  0.698376,
  0.693971,
  0.689541,
  0.685084,
  0.680601,
  0.676093,
  0.671559,
  0.667000,
  0.662416,
  0.657807,
  0.653173,
  0.648514,
  0.643832,
  0.639124,
  0.634393,
  0.629638,
  0.624859,
  0.620057,
  0.615232,
  0.610383,
  0.605511,
  0.600616,
  0.595699,
  0.590760,
  0.585798,
  0.580814,
  0.575808,
  0.570781,
  0.565732,
  0.560662,
  0.555570,
  0.550458,
  0.545325,
  0.540171,
  0.534998,
  0.529804,
  0.524590,
  0.519356,
  0.514103,
  0.508830,
  0.503538,
  0.498228,
  0.492898,
  0.487550,
  0.482184,
  0.476799,
  0.471397,
  0.465976,
  0.460539,
  0.455084,
  0.449611,
  0.444122,
  0.438616,
  0.433094,
  0.427555,
  0.422000,
  0.416430,
  0.410843,
  0.405241,
  0.399624,
  0.393992,
  0.388345,
  0.382683,
  0.377007,
  0.371317,
  0.365613,
  0.359895,
  0.354164,
  0.348419,
  0.342661,
  0.336890,
  0.331106,
  0.325310,
  0.319502,
  0.313682,
  0.307850,
  0.302006,
  0.296151,
  0.290285,
  0.284408,
  0.278520,
  0.272621,
  0.266713,
  0.260794,
  0.254866,
  0.248928,
  0.242980,
  0.237024,
  0.231058,
  0.225084,
  0.219101,
  0.213110,
  0.207111,
  0.201105,
  0.195090,
  0.189069,
  0.183040,
  0.177004,
  0.170962,
  0.164913,
  0.158858,
  0.152797,
  0.146730,
  0.140658,
  0.134581,
  0.128498,
  0.122411,
  0.116319,
  0.110222,
  0.104122,
  0.098017,
  0.091909,
  0.085797,
  0.079682,
  0.073565,
  0.067444,
  0.061321,
  0.055195,
  0.049068,
  0.042938,
  0.036807,
  0.030675,
  0.024541,
  0.018407,
  0.012272,
  0.006136,
  0.000000,
  -0.006136,
  -0.012272,
  -0.018407,
  -0.024541,
  -0.030675,
  -0.036807,
  -0.042938,
  -0.049068,
  -0.055195,
  -0.061321,
  -0.067444,
  -0.073565,
  -0.079682,
  -0.085797,
  -0.091909,
  -0.098017,
  -0.104122,
  -0.110222,
  -0.116319,
  -0.122411,
  -0.128498,
  -0.134581,
  -0.140658,
  -0.146730,
  -0.152797,
  -0.158858,
  -0.164913,
  -0.170962,
  -0.177004,
  -0.183040,
  -0.189069,
  -0.195090,
  -0.201105,
  -0.207111,
  -0.213110,
  -0.219101,
  -0.225084,
  -0.231058,
  -0.237024,
  -0.242980,
  -0.248928,
  -0.254866,
  -0.260794,
  -0.266713,
  -0.272621,
  -0.278520,
  -0.284408,
  -0.290285,
  -0.296151,
  -0.302006,
  -0.307850,
  -0.313682,
  -0.319502,
  -0.325310,
  -0.331106,
  -0.336890,
  -0.342661,
  -0.348419,
  -0.354164,
  -0.359895,
  -0.365613,
  -0.371317,
  -0.377007,
  -0.382683,
  -0.388345,
  -0.393992,
  -0.399624,
  -0.405241,
  -0.410843,
  -0.416430,
  -0.422000,
  -0.427555,
  -0.433094,
  -0.438616,
  -0.444122,
  -0.449611,
  -0.455084,
  -0.460539,
  -0.465976,
  -0.471397,
  -0.476799,
  -0.482184,
  -0.487550,
  -0.492898,
  -0.498228,
  -0.503538,
  -0.508830,
  -0.514103,
  -0.519356,
  -0.524590,
  -0.529804,
  -0.534998,
  -0.540171,
  -0.545325,
  -0.550458,
  -0.555570,
  -0.560662,
  -0.565732,
  -0.570781,
  -0.575808,
  -0.580814,
  -0.585798,
  -0.590760,
  -0.595699,
  -0.600616,
  -0.605511,
  -0.610383,
  -0.615232,
  -0.620057,
  -0.624859,
  -0.629638,
  -0.634393,
  -0.639124,
  -0.643832,
  -0.648514,
  -0.653173,
  -0.657807,
  -0.662416,
  -0.667000,
  -0.671559,
  -0.676093,
  -0.680601,
  -0.685084,
  -0.689541,
  -0.693971,
  -0.698376,
  -0.702755,
  -0.707107,
  -0.711432,
  -0.715731,
  -0.720003,
  -0.724247,
  -0.728464,
  -0.732654,
  -0.736817,
  -0.740951,
  -0.745058,
  -0.749136,
  -0.753187,
  -0.757209,
  -0.761202,
  -0.765167,
  -0.769103,
  -0.773010,
  -0.776888,
  -0.780737,
  -0.784557,
  -0.788346,
  -0.792107,
  -0.795837,
  -0.799537,
  -0.803208,
  -0.806848,
  -0.810457,
  -0.814036,
  -0.817585,
  -0.821103,
  -0.824589,
  -0.828045,
  -0.831470,
  -0.834863,
  -0.838225,
  -0.841555,
  -0.844854,
  -0.848120,
  -0.851355,
  -0.854558,
  -0.857729,
  -0.860867,
  -0.863973,
  -0.867046,
  -0.870087,
  -0.873095,
  -0.876070,
  -0.879012,
  -0.881921,
  -0.884797,
  -0.887640,
  -0.890449,
  -0.893224,
  -0.895966,
  -0.898674,
  -0.901349,
  -0.903989,
  -0.906596,
  -0.909168,
  -0.911706,
  -0.914210,
  -0.916679,
  -0.919114,
  -0.921514,
  -0.923880,
  -0.926210,
  -0.928506,
  -0.930767,
  -0.932993,
  -0.935184,
  -0.937339,
  -0.939459,
  -0.941544,
  -0.943593,
  -0.945607,
  -0.947586,
  -0.949528,
  -0.951435,
  -0.953306,
  -0.955141,
  -0.956940,
  -0.958703,
  -0.960431,
  -0.962121,
  -0.963776,
  -0.965394,
  -0.966976,
  -0.968522,
  -0.970031,
  -0.971504,
  -0.972940,
  -0.974339,
  -0.975702,
  -0.977028,
  -0.978317,
  -0.979570,
  -0.980785,
  -0.981964,
  -0.983105,
  -0.984210,
  -0.985278,
  -0.986308,
  -0.987301,
  -0.988258,
  -0.989177,
  -0.990058,
  -0.990903,
  -0.991710,
  -0.992480,
  -0.993212,
  -0.993907,
  -0.994565,
  -0.995185,
  -0.995767,
  -0.996313,
  -0.996820,
  -0.997290,
  -0.997723,
  -0.998118,
  -0.998476,
  -0.998795,
  -0.999078,
  -0.999322,
  -0.999529,
  -0.999699,
  -0.999831,
  -0.999925,
  -0.999981,
  -1.000000,
  -0.999981,
  -0.999925,
  -0.999831,
  -0.999699,
  -0.999529,
  -0.999322,
  -0.999078,
  -0.998795,
  -0.998476,
  -0.998118,
  -0.997723,
  -0.997290,
  -0.996820,
  -0.996313,
  -0.995767,
  -0.995185,
  -0.994565,
  -0.993907,
  -0.993212,
  -0.992480,
  -0.991710,
  -0.990903,
  -0.990058,
  -0.989177,
  -0.988258,
  -0.987301,
  -0.986308,
  -0.985278,
  -0.984210,
  -0.983105,
  -0.981964,
  -0.980785,
  -0.979570,
  -0.978317,
  -0.977028,
  -0.975702,
  -0.974339,
  -0.972940,
  -0.971504,
  -0.970031,
  -0.968522,
  -0.966976,
  -0.965394,
  -0.963776,
  -0.962121,
  -0.960431,
  -0.958703,
  -0.956940,
  -0.955141,
  -0.953306,
  -0.951435,
  -0.949528,
  -0.947586,
  -0.945607,
  -0.943593,
  -0.941544,
  -0.939459,
  -0.937339,
  -0.935184,
  -0.932993,
  -0.930767,
  -0.928506,
  -0.926210,
  -0.923880,
  -0.921514,
  -0.919114,
  -0.916679,
  -0.914210,
  -0.911706,
  -0.909168,
  -0.906596,
  -0.903989,
  -0.901349,
  -0.898674,
  -0.895966,
  -0.893224,
  -0.890449,
  -0.887640,
  -0.884797,
  -0.881921,
  -0.879012,
  -0.876070,
  -0.873095,
  -0.870087,
  -0.867046,
  -0.863973,
  -0.860867,
  -0.857729,
  -0.854558,
  -0.851355,
  -0.848120,
  -0.844854,
  -0.841555,
  -0.838225,
  -0.834863,
  -0.831470,
  -0.828045,
  -0.824589,
  -0.821103,
  -0.817585,
  -0.814036,
  -0.810457,
  -0.806848,
  -0.803208,
  -0.799537,
  -0.795837,
  -0.792107,
  -0.788346,
  -0.784557,
  -0.780737,
  -0.776888,
  -0.773010,
  -0.769103,
  -0.765167,
  -0.761202,
  -0.757209,
  -0.753187,
  -0.749136,
  -0.745058,
  -0.740951,
  -0.736817,
  -0.732654,
  -0.728464,
  -0.724247,
  -0.720003,
  -0.715731,
  -0.711432,
  -0.707107,
  -0.702755,
  -0.698376,
  -0.693971,
  -0.689541,
  -0.685084,
  -0.680601,
  -0.676093,
  -0.671559,
  -0.667000,
  -0.662416,
  -0.657807,
  -0.653173,
  -0.648514,
  -0.643832,
  -0.639124,
  -0.634393,
  -0.629638,
  -0.624859,
  -0.620057,
  -0.615232,
  -0.610383,
  -0.605511,
  -0.600616,
  -0.595699,
  -0.590760,
  -0.585798,
  -0.580814,
  -0.575808,
  -0.570781,
  -0.565732,
  -0.560662,
  -0.555570,
  -0.550458,
  -0.545325,
  -0.540171,
  -0.534998,
  -0.529804,
  -0.524590,
  -0.519356,
  -0.514103,
  -0.508830,
  -0.503538,
  -0.498228,
  -0.492898,
  -0.487550,
  -0.482184,
  -0.476799,
  -0.471397,
  -0.465976,
  -0.460539,
  -0.455084,
  -0.449611,
  -0.444122,
  -0.438616,
  -0.433094,
  -0.427555,
  -0.422000,
  -0.416430,
  -0.410843,
  -0.405241,
  -0.399624,
  -0.393992,
  -0.388345,
  -0.382683,
  -0.377007,
  -0.371317,
  -0.365613,
  -0.359895,
  -0.354164,
  -0.348419,
  -0.342661,
  -0.336890,
  -0.331106,
  -0.325310,
  -0.319502,
  -0.313682,
  -0.307850,
  -0.302006,
  -0.296151,
  -0.290285,
  -0.284408,
  -0.278520,
  -0.272621,
  -0.266713,
  -0.260794,
  -0.254866,
  -0.248928,
  -0.242980,
  -0.237024,
  -0.231058,
  -0.225084,
  -0.219101,
  -0.213110,
  -0.207111,
  -0.201105,
  -0.195090,
  -0.189069,
  -0.183040,
  -0.177004,
  -0.170962,
  -0.164913,
  -0.158858,
  -0.152797,
  -0.146730,
  -0.140658,
  -0.134581,
  -0.128498,
  -0.122411,
  -0.116319,
  -0.110222,
  -0.104122,
  -0.098017,
  -0.091909,
  -0.085797,
  -0.079682,
  -0.073565,
  -0.067444,
  -0.061321,
  -0.055195,
  -0.049068,
  -0.042938,
  -0.036807,
  -0.030675,
  -0.024541,
  -0.018407,
  -0.012272,
  -0.006136,
};

const float cosTable[MATH_TABLE_SIZE] =
{
  1.000000,
  0.999981,
  0.999925,
  0.999831,
  0.999699,
  0.999529,
  0.999322,
  0.999078,
  0.998795,
  0.998476,
  0.998118,
  0.997723,
  0.997290,
  0.996820,
  0.996313,
  0.995767,
  0.995185,
  0.994565,
  0.993907,
  0.993212,
  0.992480,
  0.991710,
  0.990903,
  0.990058,
  0.989177,
  0.988258,
  0.987301,
  0.986308,
  0.985278,
  0.984210,
  0.983105,
  0.981964,
  0.980785,
  0.979570,
  0.978317,
  0.977028,
  0.975702,
  0.974339,
  0.972940,
  0.971504,
  0.970031,
  0.968522,
  0.966976,
  0.965394,
  0.963776,
  0.962121,
  0.960431,
  0.958703,
  0.956940,
  0.955141,
  0.953306,
  0.951435,
  0.949528,
  0.947586,
  0.945607,
  0.943593,
  0.941544,
  0.939459,
  0.937339,
  0.935184,
  0.932993,
  0.930767,
  0.928506,
  0.926210,
  0.923880,
  0.921514,
  0.919114,
  0.916679,
  0.914210,
  0.911706,
  0.909168,
  0.906596,
  0.903989,
  0.901349,
  0.898674,
  0.895966,
  0.893224,
  0.890449,
  0.887640,
  0.884797,
  0.881921,
  0.879012,
  0.876070,
  0.873095,
  0.870087,
  0.867046,
  0.863973,
  0.860867,
  0.857729,
  0.854558,
  0.851355,
  0.848120,
  0.844854,
  0.841555,
  0.838225,
  0.834863,
  0.831470,
  0.828045,
  0.824589,
  0.821103,
  0.817585,
  0.814036,
  0.810457,
  0.806848,
  0.803208,
  0.799537,
  0.795837,
  0.792107,
  0.788346,
  0.784557,
  0.780737,
  0.776888,
  0.773010,
  0.769103,
  0.765167,
  0.761202,
  0.757209,
  0.753187,
  0.749136,
  0.745058,
  0.740951,
  0.736817,
  0.732654,
  0.728464,
  0.724247,
  0.720003,
  0.715731,
  0.711432,
  0.707107,
  0.702755,
  0.698376,
  0.693971,
  0.689541,
  0.685084,
  0.680601,
  0.676093,
  0.671559,
  0.667000,
  0.662416,
  0.657807,
  0.653173,
  0.648514,
  0.643832,
  0.639124,
  0.634393,
  0.629638,
  0.624859,
  0.620057,
  0.615232,
  0.610383,
  0.605511,
  0.600616,
  0.595699,
  0.590760,
  0.585798,
  0.580814,
  0.575808,
  0.570781,
  0.565732,
  0.560662,
  0.555570,
  0.550458,
  0.545325,
  0.540171,
  0.534998,
  0.529804,
  0.524590,
  0.519356,
  0.514103,
  0.508830,
  0.503538,
  0.498228,
  0.492898,
  0.487550,
  0.482184,
  0.476799,
  0.471397,
  0.465976,
  0.460539,
  0.455084,
  0.449611,
  0.444122,
  0.438616,
  0.433094,
  0.427555,
  0.422000,
  0.416430,
  0.410843,
  0.405241,
  0.399624,
  0.393992,
  0.388345,
  0.382683,
  0.377007,
  0.371317,
  0.365613,
  0.359895,
  0.354164,
  0.348419,
  0.342661,
  0.336890,
  0.331106,
  0.325310,
  0.319502,
  0.313682,
  0.307850,
  0.302006,
  0.296151,
  0.290285,
  0.284408,
  0.278520,
  0.272621,
  0.266713,
  0.260794,
  0.254866,
  0.248928,
  0.242980,
  0.237024,
  0.231058,
  0.225084,
  0.219101,
  0.213110,
  0.207111,
  0.201105,
  0.195090,
  0.189069,
  0.183040,
  0.177004,
  0.170962,
  0.164913,
  0.158858,
  0.152797,
  0.146730,
  0.140658,
  0.134581,
  0.128498,
  0.122411,
  0.116319,
  0.110222,
  0.104122,
  0.098017,
  0.091909,
  0.085797,
  0.079682,
  0.073565,
  0.067444,
  0.061321,
  0.055195,
  0.049068,
  0.042938,
  0.036807,
  0.030675,
  0.024541,
  0.018407,
  0.012272,
  0.006136,
  0.000000,
  -0.006136,
  -0.012272,
  -0.018407,
  -0.024541,
  -0.030675,
  -0.036807,
  -0.042938,
  -0.049068,
  -0.055195,
  -0.061321,
  -0.067444,
  -0.073565,
  -0.079682,
  -0.085797,
  -0.091909,
  -0.098017,
  -0.104122,
  -0.110222,
  -0.116319,
  -0.122411,
  -0.128498,
  -0.134581,
  -0.140658,
  -0.146730,
  -0.152797,
  -0.158858,
  -0.164913,
  -0.170962,
  -0.177004,
  -0.183040,
  -0.189069,
  -0.195090,
  -0.201105,
  -0.207111,
  -0.213110,
  -0.219101,
  -0.225084,
  -0.231058,
  -0.237024,
  -0.242980,
  -0.248928,
  -0.254866,
  -0.260794,
  -0.266713,
  -0.272621,
  -0.278520,
  -0.284408,
  -0.290285,
  -0.296151,
  -0.302006,
  -0.307850,
  -0.313682,
  -0.319502,
  -0.325310,
  -0.331106,
  -0.336890,
  -0.342661,
  -0.348419,
  -0.354164,
  -0.359895,
  -0.365613,
  -0.371317,
  -0.377007,
  -0.382683,
  -0.388345,
  -0.393992,
  -0.399624,
  -0.405241,
  -0.410843,
  -0.416430,
  -0.422000,
  -0.427555,
  -0.433094,
  -0.438616,
  -0.444122,
  -0.449611,
  -0.455084,
  -0.460539,
  -0.465976,
  -0.471397,
  -0.476799,
  -0.482184,
  -0.487550,
  -0.492898,
  -0.498228,
  -0.503538,
  -0.508830,
  -0.514103,
  -0.519356,
  -0.524590,
  -0.529804,
  -0.534998,
  -0.540171,
  -0.545325,
  -0.550458,
  -0.555570,
  -0.560662,
  -0.565732,
  -0.570781,
  -0.575808,
  -0.580814,
  -0.585798,
  -0.590760,
  -0.595699,
  -0.600616,
  -0.605511,
  -0.610383,
  -0.615232,
  -0.620057,
  -0.624859,
  -0.629638,
  -0.634393,
  -0.639124,
  -0.643832,
  -0.648514,
  -0.653173,
  -0.657807,
  -0.662416,
  -0.667000,
  -0.671559,
  -0.676093,
  -0.680601,
  -0.685084,
  -0.689541,
  -0.693971,
  -0.698376,
  -0.702755,
  -0.707107,
  -0.711432,
  -0.715731,
  -0.720003,
  -0.724247,
  -0.728464,
  -0.732654,
  -0.736817,
  -0.740951,
  -0.745058,
  -0.749136,
  -0.753187,
  -0.757209,
  -0.761202,
  -0.765167,
  -0.769103,
  -0.773010,
  -0.776888,
  -0.780737,
  -0.784557,
  -0.788346,
  -0.792107,
  -0.795837,
  -0.799537,
  -0.803208,
  -0.806848,
  -0.810457,
  -0.814036,
  -0.817585,
  -0.821103,
  -0.824589,
  -0.828045,
  -0.831470,
  -0.834863,
  -0.838225,
  -0.841555,
  -0.844854,
  -0.848120,
  -0.851355,
  -0.854558,
  -0.857729,
  -0.860867,
  -0.863973,
  -0.867046,
  -0.870087,
  -0.873095,
  -0.876070,
  -0.879012,
  -0.881921,
  -0.884797,
  -0.887640,
  -0.890449,
  -0.893224,
  -0.895966,
  -0.898674,
  -0.901349,
  -0.903989,
  -0.906596,
  -0.909168,
  -0.911706,
  -0.914210,
  -0.916679,
  -0.919114,
  -0.921514,
  -0.923880,
  -0.926210,
  -0.928506,
  -0.930767,
  -0.932993,
  -0.935184,
  -0.937339,
  -0.939459,
  -0.941544,
  -0.943593,
  -0.945607,
  -0.947586,
  -0.949528,
  -0.951435,
  -0.953306,
  -0.955141,
  -0.956940,
  -0.958703,
  -0.960431,
  -0.962121,
  -0.963776,
  -0.965394,
  -0.966976,
  -0.968522,
  -0.970031,
  -0.971504,
  -0.972940,
  -0.974339,
  -0.975702,
  -0.977028,
  -0.978317,
  -0.979570,
  -0.980785,
  -0.981964,
  -0.983105,
  -0.984210,
  -0.985278,
  -0.986308,
  -0.987301,
  -0.988258,
  -0.989177,
  -0.990058,
  -0.990903,
  -0.991710,
  -0.992480,
  -0.993212,
  -0.993907,
  -0.994565,
  -0.995185,
  -0.995767,
  -0.996313,
  -0.996820,
  -0.997290,
  -0.997723,
  -0.998118,
  -0.998476,
  -0.998795,
  -0.999078,
  -0.999322,
  -0.999529,
  -0.999699,
  -0.999831,
  -0.999925,
  -0.999981,
  -1.000000,
  -0.999981,
  -0.999925,
  -0.999831,
  -0.999699,
  -0.999529,
  -0.999322,
  -0.999078,
  -0.998795,
  -0.998476,
  -0.998118,
  -0.997723,
  -0.997290,
  -0.996820,
  -0.996313,
  -0.995767,
  -0.995185,
  -0.994565,
  -0.993907,
  -0.993212,
  -0.992480,
  -0.991710,
  -0.990903,
  -0.990058,
  -0.989177,
  -0.988258,
  -0.987301,
  -0.986308,
  -0.985278,
  -0.984210,
  -0.983105,
  -0.981964,
  -0.980785,
  -0.979570,
  -0.978317,
  -0.977028,
  -0.975702,
  -0.974339,
  -0.972940,
  -0.971504,
  -0.970031,
  -0.968522,
  -0.966976,
  -0.965394,
  -0.963776,
  -0.962121,
  -0.960431,
  -0.958703,
  -0.956940,
  -0.955141,
  -0.953306,
  -0.951435,
  -0.949528,
  -0.947586,
  -0.945607,
  -0.943593,
  -0.941544,
  -0.939459,
  -0.937339,
  -0.935184,
  -0.932993,
  -0.930767,
  -0.928506,
  -0.926210,
  -0.923880,
  -0.921514,
  -0.919114,
  -0.916679,
  -0.914210,
  -0.911706,
  -0.909168,
  -0.906596,
  -0.903989,
  -0.901349,
  -0.898674,
  -0.895966,
  -0.893224,
  -0.890449,
  -0.887640,
  -0.884797,
  -0.881921,
  -0.879012,
  -0.876070,
  -0.873095,
  -0.870087,
  -0.867046,
  -0.863973,
  -0.860867,
  -0.857729,
  -0.854558,
  -0.851355,
  -0.848120,
  -0.844854,
  -0.841555,
  -0.838225,
  -0.834863,
  -0.831470,
  -0.828045,
  -0.824589,
  -0.821103,
  -0.817585,
  -0.814036,
  -0.810457,
  -0.806848,
  -0.803208,
  -0.799537,
  -0.795837,
  -0.792107,
  -0.788346,
  -0.784557,
  -0.780737,
  -0.776888,
  -0.773010,
  -0.769103,
  -0.765167,
  -0.761202,
  -0.757209,
  -0.753187,
  -0.749136,
  -0.745058,
  -0.740951,
  -0.736817,
  -0.732654,
  -0.728464,
  -0.724247,
  -0.720003,
  -0.715731,
  -0.711432,
  -0.707107,
  -0.702755,
  -0.698376,
  -0.693971,
  -0.689541,
  -0.685084,
  -0.680601,
  -0.676093,
  -0.671559,
  -0.667000,
  -0.662416,
  -0.657807,
  -0.653173,
  -0.648514,
  -0.643832,
  -0.639124,
  -0.634393,
  -0.629638,
  -0.624859,
  -0.620057,
  -0.615232,
  -0.610383,
  -0.605511,
  -0.600616,
  -0.595699,
  -0.590760,
  -0.585798,
  -0.580814,
  -0.575808,
  -0.570781,
  -0.565732,
  -0.560662,
  -0.555570,
  -0.550458,
  -0.545325,
  -0.540171,
  -0.534998,
  -0.529804,
  -0.524590,
  -0.519356,
  -0.514103,
  -0.508830,
  -0.503538,
  -0.498228,
  -0.492898,
  -0.487550,
  -0.482184,
  -0.476799,
  -0.471397,
  -0.465976,
  -0.460539,
  -0.455084,
  -0.449611,
  -0.444122,
  -0.438616,
  -0.433094,
  -0.427555,
  -0.422000,
  -0.416430,
  -0.410843,
  -0.405241,
  -0.399624,
  -0.393992,
  -0.388345,
  -0.382683,
  -0.377007,
  -0.371317,
  -0.365613,
  -0.359895,
  -0.354164,
  -0.348419,
  -0.342661,
  -0.336890,
  -0.331106,
  -0.325310,
  -0.319502,
  -0.313682,
  -0.307850,
  -0.302006,
  -0.296151,
  -0.290285,
  -0.284408,
  -0.278520,
  -0.272621,
  -0.266713,
  -0.260794,
  -0.254866,
  -0.248928,
  -0.242980,
  -0.237024,
  -0.231058,
  -0.225084,
  -0.219101,
  -0.213110,
  -0.207111,
  -0.201105,
  -0.195090,
  -0.189069,
  -0.183040,
  -0.177004,
  -0.170962,
  -0.164913,
  -0.158858,
  -0.152797,
  -0.146730,
  -0.140658,
  -0.134581,
  -0.128498,
  -0.122411,
  -0.116319,
  -0.110222,
  -0.104122,
  -0.098017,
  -0.091909,
  -0.085797,
  -0.079682,
  -0.073565,
  -0.067444,
  -0.061321,
  -0.055195,
  -0.049068,
  -0.042938,
  -0.036807,
  -0.030675,
  -0.024541,
  -0.018407,
  -0.012272,
  -0.006136,
  -0.000000,
  0.006136,
  0.012272,
  0.018407,
  0.024541,
  0.030675,
  0.036807,
  0.042938,
  0.049068,
  0.055195,
  0.061321,
  0.067444,
  0.073565,
  0.079682,
  0.085797,
  0.091909,
  0.098017,
  0.104122,
  0.110222,
  0.116319,
  0.122411,
  0.128498,
  0.134581,
  0.140658,
  0.146730,
  0.152797,
  0.158858,
  0.164913,
  0.170962,
  0.177004,
  0.183040,
  0.189069,
  0.195090,
  0.201105,
  0.207111,
  0.213110,
  0.219101,
  0.225084,
  0.231058,
  0.237024,
  0.242980,
  0.248928,
  0.254866,
  0.260794,
  0.266713,
  0.272621,
  0.278520,
  0.284408,
  0.290285,
  0.296151,
  0.302006,
  0.307850,
  0.313682,
  0.319502,
  0.325310,
  0.331106,
  0.336890,
  0.342661,
  0.348419,
  0.354164,
  0.359895,
  0.365613,
  0.371317,
  0.377007,
  0.382683,
  0.388345,
  0.393992,
  0.399624,
  0.405241,
  0.410843,
  0.416430,
  0.422000,
  0.427555,
  0.433094,
  0.438616,
  0.444122,
  0.449611,
  0.455084,
  0.460539,
  0.465976,
  0.471397,
  0.476799,
  0.482184,
  0.487550,
  0.492898,
  0.498228,
  0.503538,
  0.508830,
  0.514103,
  0.519356,
  0.524590,
  0.529804,
  0.534998,
  0.540171,
  0.545325,
  0.550458,
  0.555570,
  0.560662,
  0.565732,
  0.570781,
  0.575808,
  0.580814,
  0.585798,
  0.590760,
  0.595699,
  0.600616,
  0.605511,
  0.610383,
  0.615232,
  0.620057,
  0.624859,
  0.629638,
  0.634393,
  0.639124,
  0.643832,
  0.648514,
  0.653173,
  0.657807,
  0.662416,
  0.667000,
  0.671559,
  0.676093,
  0.680601,
  0.685084,
  0.689541,
  0.693971,
  0.698376,
  0.702755,
  0.707107,
  0.711432,
  0.715731,
  0.720003,
  0.724247,
  0.728464,
  0.732654,
  0.736817,
  0.740951,
  0.745058,
  0.749136,
  0.753187,
  0.757209,
  0.761202,
  0.765167,
  0.769103,
  0.773010,
  0.776888,
  0.780737,
  0.784557,
  0.788346,
  0.792107,
  0.795837,
  0.799537,
  0.803208,
  0.806848,
  0.810457,
  0.814036,
  0.817585,
  0.821103,
  0.824589,
  0.828045,
  0.831470,
  0.834863,
  0.838225,
  0.841555,
  0.844854,
  0.848120,
  0.851355,
  0.854558,
  0.857729,
  0.860867,
  0.863973,
  0.867046,
  0.870087,
  0.873095,
  0.876070,
  0.879012,
  0.881921,
  0.884797,
  0.887640,
  0.890449,
  0.893224,
  0.895966,
  0.898674,
  0.901349,
  0.903989,
  0.906596,
  0.909168,
  0.911706,
  0.914210,
  0.916679,
  0.919114,
  0.921514,
  0.923880,
  0.926210,
  0.928506,
  0.930767,
  0.932993,
  0.935184,
  0.937339,
  0.939459,
  0.941544,
  0.943593,
  0.945607,
  0.947586,
  0.949528,
  0.951435,
  0.953306,
  0.955141,
  0.956940,
  0.958703,
  0.960431,
  0.962121,
  0.963776,
  0.965394,
  0.966976,
  0.968522,
  0.970031,
  0.971504,
  0.972940,
  0.974339,
  0.975702,
  0.977028,
  0.978317,
  0.979570,
  0.980785,
  0.981964,
  0.983105,
  0.984210,
  0.985278,
  0.986308,
  0.987301,
  0.988258,
  0.989177,
  0.990058,
  0.990903,
  0.991710,
  0.992480,
  0.993212,
  0.993907,
  0.994565,
  0.995185,
  0.995767,
  0.996313,
  0.996820,
  0.997290,
  0.997723,
  0.998118,
  0.998476,
  0.998795,
  0.999078,
  0.999322,
  0.999529,
  0.999699,
  0.999831,
  0.999925,
  0.999981,
};

const float tanTable[MATH_TABLE_SIZE] =
{
  0.000000,
  0.006136,
  0.012272,
  0.018410,
  0.024549,
  0.030689,
  0.036832,
  0.042978,
  0.049127,
  0.055280,
  0.061436,
  0.067598,
  0.073764,
  0.079937,
  0.086115,
  0.092300,
  0.098491,
  0.104691,
  0.110898,
  0.117114,
  0.123338,
  0.129572,
  0.135816,
  0.142071,
  0.148336,
  0.154613,
  0.160901,
  0.167202,
  0.173516,
  0.179844,
  0.186185,
  0.192541,
  0.198912,
  0.205299,
  0.211702,
  0.218121,
  0.224558,
  0.231012,
  0.237484,
  0.243976,
  0.250487,
  0.257018,
  0.263570,
  0.270143,
  0.276737,
  0.283354,
  0.289995,
  0.296659,
  0.303347,
  0.310060,
  0.316799,
  0.323563,
  0.330355,
  0.337175,
  0.344023,
  0.350899,
  0.357806,
  0.364743,
  0.371710,
  0.378710,
  0.385743,
  0.392808,
  0.399908,
  0.407043,
  0.414214,
  0.421421,
  0.428665,
  0.435948,
  0.443270,
  0.450631,
  0.458034,
  0.465478,
  0.472965,
  0.480495,
  0.488070,
  0.495691,
  0.503358,
  0.511072,
  0.518835,
  0.526648,
  0.534511,
  0.542426,
  0.550394,
  0.558416,
  0.566493,
  0.574626,
  0.582817,
  0.591067,
  0.599377,
  0.607748,
  0.616182,
  0.624680,
  0.633243,
  0.641873,
  0.650571,
  0.659339,
  0.668179,
  0.677091,
  0.686077,
  0.695139,
  0.704279,
  0.713499,
  0.722799,
  0.732183,
  0.741651,
  0.751205,
  0.760848,
  0.770582,
  0.780408,
  0.790328,
  0.800345,
  0.810462,
  0.820679,
  0.830999,
  0.841426,
  0.851961,
  0.862606,
  0.873365,
  0.884239,
  0.895232,
  0.906347,
  0.917586,
  0.928952,
  0.940449,
  0.952079,
  0.963846,
  0.975753,
  0.987803,
  1.000000,
  1.012348,
  1.024850,
  1.037510,
  1.050333,
  1.063322,
  1.076481,
  1.089816,
  1.103330,
  1.117028,
  1.130916,
  1.144997,
  1.159278,
  1.173763,
  1.188459,
  1.203370,
  1.218504,
  1.233865,
  1.249460,
  1.265297,
  1.281382,
  1.297721,
  1.314323,
  1.331194,
  1.348344,
  1.365780,
  1.383510,
  1.401544,
  1.419891,
  1.438560,
  1.457562,
  1.476907,
  1.496606,
  1.516670,
  1.537110,
  1.557940,
  1.579173,
  1.600820,
  1.622897,
  1.645419,
  1.668399,
  1.691855,
  1.715803,
  1.740261,
  1.765247,
  1.790780,
  1.816880,
  1.843569,
  1.870868,
  1.898802,
  1.927394,
  1.956671,
  1.986659,
  2.017387,
  2.048886,
  2.081186,
  2.114322,
  2.148330,
  2.183246,
  2.219110,
  2.255964,
  2.293853,
  2.332823,
  2.372926,
  2.414214,
  2.456743,
  2.500574,
  2.545771,
  2.592403,
  2.640542,
  2.690266,
  2.741660,
  2.794813,
  2.849820,
  2.906786,
  2.965820,
  3.027043,
  3.090584,
  3.156580,
  3.225184,
  3.296558,
  3.370879,
  3.448340,
  3.529149,
  3.613536,
  3.701749,
  3.794063,
  3.890778,
  3.992224,
  4.098764,
  4.210802,
  4.328783,
  4.453202,
  4.584612,
  4.723629,
  4.870946,
  5.027339,
  5.193689,
  5.370990,
  5.560376,
  5.763142,
  5.980774,
  6.214988,
  6.467773,
  6.741452,
  7.038750,
  7.362888,
  7.717699,
  8.107786,
  8.538718,
  9.017302,
  9.551949,
  10.153170,
  10.834280,
  11.612399,
  12.509912,
  13.556669,
  14.793373,
  16.277008,
  18.089884,
  20.355468,
  23.267776,
  27.150171,
  32.584705,
  40.735484,
  54.318751,
  81.483240,
  162.972616,
  16331778728383844.000000,
  -162.972616,
  -81.483240,
  -54.318751,
  -40.735484,
  -32.584705,
  -27.150171,
  -23.267776,
  -20.355468,
  -18.089884,
  -16.277008,
  -14.793373,
  -13.556669,
  -12.509912,
  -11.612399,
  -10.834280,
  -10.153170,
  -9.551949,
  -9.017302,
  -8.538718,
  -8.107786,
  -7.717699,
  -7.362888,
  -7.038750,
  -6.741452,
  -6.467773,
  -6.214988,
  -5.980774,
  -5.763142,
  -5.560376,
  -5.370990,
  -5.193689,
  -5.027339,
  -4.870946,
  -4.723629,
  -4.584612,
  -4.453202,
  -4.328783,
  -4.210802,
  -4.098764,
  -3.992224,
  -3.890778,
  -3.794063,
  -3.701749,
  -3.613536,
  -3.529149,
  -3.448340,
  -3.370879,
  -3.296558,
  -3.225184,
  -3.156580,
  -3.090584,
  -3.027043,
  -2.965820,
  -2.906786,
  -2.849820,
  -2.794813,
  -2.741660,
  -2.690266,
  -2.640542,
  -2.592403,
  -2.545771,
  -2.500574,
  -2.456743,
  -2.414214,
  -2.372926,
  -2.332823,
  -2.293853,
  -2.255964,
  -2.219110,
  -2.183246,
  -2.148330,
  -2.114322,
  -2.081186,
  -2.048886,
  -2.017387,
  -1.986659,
  -1.956671,
  -1.927394,
  -1.898802,
  -1.870868,
  -1.843569,
  -1.816880,
  -1.790780,
  -1.765247,
  -1.740261,
  -1.715803,
  -1.691855,
  -1.668399,
  -1.645419,
  -1.622897,
  -1.600820,
  -1.579173,
  -1.557940,
  -1.537110,
  -1.516670,
  -1.496606,
  -1.476907,
  -1.457562,
  -1.438560,
  -1.419891,
  -1.401544,
  -1.383510,
  -1.365780,
  -1.348344,
  -1.331194,
  -1.314323,
  -1.297721,
  -1.281382,
  -1.265297,
  -1.249460,
  -1.233865,
  -1.218504,
  -1.203370,
  -1.188459,
  -1.173763,
  -1.159278,
  -1.144997,
  -1.130916,
  -1.117028,
  -1.103330,
  -1.089816,
  -1.076481,
  -1.063322,
  -1.050333,
  -1.037510,
  -1.024850,
  -1.012348,
  -1.000000,
  -0.987803,
  -0.975753,
  -0.963846,
  -0.952079,
  -0.940449,
  -0.928952,
  -0.917586,
  -0.906347,
  -0.895232,
  -0.884239,
  -0.873365,
  -0.862606,
  -0.851961,
  -0.841426,
  -0.830999,
  -0.820679,
  -0.810462,
  -0.800345,
  -0.790328,
  -0.780408,
  -0.770582,
  -0.760848,
  -0.751205,
  -0.741651,
  -0.732183,
  -0.722799,
  -0.713499,
  -0.704279,
  -0.695139,
  -0.686077,
  -0.677091,
  -0.668179,
  -0.659339,
  -0.650571,
  -0.641873,
  -0.633243,
  -0.624680,
  -0.616182,
  -0.607748,
  -0.599377,
  -0.591067,
  -0.582817,
  -0.574626,
  -0.566493,
  -0.558416,
  -0.550394,
  -0.542426,
  -0.534511,
  -0.526648,
  -0.518835,
  -0.511072,
  -0.503358,
  -0.495691,
  -0.488070,
  -0.480495,
  -0.472965,
  -0.465478,
  -0.458034,
  -0.450631,
  -0.443270,
  -0.435948,
  -0.428665,
  -0.421421,
  -0.414214,
  -0.407043,
  -0.399908,
  -0.392808,
  -0.385743,
  -0.378710,
  -0.371710,
  -0.364743,
  -0.357806,
  -0.350899,
  -0.344023,
  -0.337175,
  -0.330355,
  -0.323563,
  -0.316799,
  -0.310060,
  -0.303347,
  -0.296659,
  -0.289995,
  -0.283354,
  -0.276737,
  -0.270143,
  -0.263570,
  -0.257018,
  -0.250487,
  -0.243976,
  -0.237484,
  -0.231012,
  -0.224558,
  -0.218121,
  -0.211702,
  -0.205299,
  -0.198912,
  -0.192541,
  -0.186185,
  -0.179844,
  -0.173516,
  -0.167202,
  -0.160901,
  -0.154613,
  -0.148336,
  -0.142071,
  -0.135816,
  -0.129572,
  -0.123338,
  -0.117114,
  -0.110898,
  -0.104691,
  -0.098491,
  -0.092300,
  -0.086115,
  -0.079937,
  -0.073764,
  -0.067598,
  -0.061436,
  -0.055280,
  -0.049127,
  -0.042978,
  -0.036832,
  -0.030689,
  -0.024549,
  -0.018410,
  -0.012272,
  -0.006136,
  -0.000000,
  0.006136,
  0.012272,
  0.018410,
  0.024549,
  0.030689,
  0.036832,
  0.042978,
  0.049127,
  0.055280,
  0.061436,
  0.067598,
  0.073764,
  0.079937,
  0.086115,
  0.092300,
  0.098491,
  0.104691,
  0.110898,
  0.117114,
  0.123338,
  0.129572,
  0.135816,
  0.142071,
  0.148336,
  0.154613,
  0.160901,
  0.167202,
  0.173516,
  0.179844,
  0.186185,
  0.192541,
  0.198912,
  0.205299,
  0.211702,
  0.218121,
  0.224558,
  0.231012,
  0.237484,
  0.243976,
  0.250487,
  0.257018,
  0.263570,
  0.270143,
  0.276737,
  0.283354,
  0.289995,
  0.296659,
  0.303347,
  0.310060,
  0.316799,
  0.323563,
  0.330355,
  0.337175,
  0.344023,
  0.350899,
  0.357806,
  0.364743,
  0.371710,
  0.378710,
  0.385743,
  0.392808,
  0.399908,
  0.407043,
  0.414214,
  0.421421,
  0.428665,
  0.435948,
  0.443270,
  0.450631,
  0.458034,
  0.465478,
  0.472965,
  0.480495,
  0.488070,
  0.495691,
  0.503358,
  0.511072,
  0.518835,
  0.526648,
  0.534511,
  0.542426,
  0.550394,
  0.558416,
  0.566493,
  0.574626,
  0.582817,
  0.591067,
  0.599377,
  0.607748,
  0.616182,
  0.624680,
  0.633243,
  0.641873,
  0.650571,
  0.659339,
  0.668179,
  0.677091,
  0.686077,
  0.695139,
  0.704279,
  0.713499,
  0.722799,
  0.732183,
  0.741651,
  0.751205,
  0.760848,
  0.770582,
  0.780408,
  0.790328,
  0.800345,
  0.810462,
  0.820679,
  0.830999,
  0.841426,
  0.851961,
  0.862606,
  0.873365,
  0.884239,
  0.895232,
  0.906347,
  0.917586,
  0.928952,
  0.940449,
  0.952079,
  0.963846,
  0.975753,
  0.987803,
  1.000000,
  1.012348,
  1.024850,
  1.037510,
  1.050333,
  1.063322,
  1.076481,
  1.089816,
  1.103330,
  1.117028,
  1.130916,
  1.144997,
  1.159278,
  1.173763,
  1.188459,
  1.203370,
  1.218504,
  1.233865,
  1.249460,
  1.265297,
  1.281382,
  1.297721,
  1.314323,
  1.331194,
  1.348344,
  1.365780,
  1.383510,
  1.401544,
  1.419891,
  1.438560,
  1.457562,
  1.476907,
  1.496606,
  1.516670,
  1.537110,
  1.557940,
  1.579173,
  1.600820,
  1.622897,
  1.645419,
  1.668399,
  1.691855,
  1.715803,
  1.740261,
  1.765247,
  1.790780,
  1.816880,
  1.843569,
  1.870868,
  1.898802,
  1.927394,
  1.956671,
  1.986659,
  2.017387,
  2.048886,
  2.081186,
  2.114322,
  2.148330,
  2.183246,
  2.219110,
  2.255964,
  2.293853,
  2.332823,
  2.372926,
  2.414214,
  2.456743,
  2.500574,
  2.545771,
  2.592403,
  2.640542,
  2.690266,
  2.741660,
  2.794813,
  2.849820,
  2.906786,
  2.965820,
  3.027043,
  3.090584,
  3.156580,
  3.225184,
  3.296558,
  3.370879,
  3.448340,
  3.529149,
  3.613536,
  3.701749,
  3.794063,
  3.890778,
  3.992224,
  4.098764,
  4.210802,
  4.328783,
  4.453202,
  4.584612,
  4.723629,
  4.870946,
  5.027339,
  5.193689,
  5.370990,
  5.560376,
  5.763142,
  5.980774,
  6.214988,
  6.467773,
  6.741452,
  7.038750,
  7.362888,
  7.717699,
  8.107786,
  8.538718,
  9.017302,
  9.551949,
  10.153170,
  10.834280,
  11.612399,
  12.509912,
  13.556669,
  14.793373,
  16.277008,
  18.089884,
  20.355468,
  23.267776,
  27.150171,
  32.584705,
  40.735484,
  54.318751,
  81.483240,
  162.972616,
  5443926242794615.000000,
  -162.972616,
  -81.483240,
  -54.318751,
  -40.735484,
  -32.584705,
  -27.150171,
  -23.267776,
  -20.355468,
  -18.089884,
  -16.277008,
  -14.793373,
  -13.556669,
  -12.509912,
  -11.612399,
  -10.834280,
  -10.153170,
  -9.551949,
  -9.017302,
  -8.538718,
  -8.107786,
  -7.717699,
  -7.362888,
  -7.038750,
  -6.741452,
  -6.467773,
  -6.214988,
  -5.980774,
  -5.763142,
  -5.560376,
  -5.370990,
  -5.193689,
  -5.027339,
  -4.870946,
  -4.723629,
  -4.584612,
  -4.453202,
  -4.328783,
  -4.210802,
  -4.098764,
  -3.992224,
  -3.890778,
  -3.794063,
  -3.701749,
  -3.613536,
  -3.529149,
  -3.448340,
  -3.370879,
  -3.296558,
  -3.225184,
  -3.156580,
  -3.090584,
  -3.027043,
  -2.965820,
  -2.906786,
  -2.849820,
  -2.794813,
  -2.741660,
  -2.690266,
  -2.640542,
  -2.592403,
  -2.545771,
  -2.500574,
  -2.456743,
  -2.414214,
  -2.372926,
  -2.332823,
  -2.293853,
  -2.255964,
  -2.219110,
  -2.183246,
  -2.148330,
  -2.114322,
  -2.081186,
  -2.048886,
  -2.017387,
  -1.986659,
  -1.956671,
  -1.927394,
  -1.898802,
  -1.870868,
  -1.843569,
  -1.816880,
  -1.790780,
  -1.765247,
  -1.740261,
  -1.715803,
  -1.691855,
  -1.668399,
  -1.645419,
  -1.622897,
  -1.600820,
  -1.579173,
  -1.557940,
  -1.537110,
  -1.516670,
  -1.496606,
  -1.476907,
  -1.457562,
  -1.438560,
  -1.419891,
  -1.401544,
  -1.383510,
  -1.365780,
  -1.348344,
  -1.331194,
  -1.314323,
  -1.297721,
  -1.281382,
  -1.265297,
  -1.249460,
  -1.233865,
  -1.218504,
  -1.203370,
  -1.188459,
  -1.173763,
  -1.159278,
  -1.144997,
  -1.130916,
  -1.117028,
  -1.103330,
  -1.089816,
  -1.076481,
  -1.063322,
  -1.050333,
  -1.037510,
  -1.024850,
  -1.012348,
  -1.000000,
  -0.987803,
  -0.975753,
  -0.963846,
  -0.952079,
  -0.940449,
  -0.928952,
  -0.917586,
  -0.906347,
  -0.895232,
  -0.884239,
  -0.873365,
  -0.862606,
  -0.851961,
  -0.841426,
  -0.830999,
  -0.820679,
  -0.810462,
  -0.800345,
  -0.790328,
  -0.780408,
  -0.770582,
  -0.760848,
  -0.751205,
  -0.741651,
  -0.732183,
  -0.722799,
  -0.713499,
  -0.704279,
  -0.695139,
  -0.686077,
  -0.677091,
  -0.668179,
  -0.659339,
  -0.650571,
  -0.641873,
  -0.633243,
  -0.624680,
  -0.616182,
  -0.607748,
  -0.599377,
  -0.591067,
  -0.582817,
  -0.574626,
  -0.566493,
  -0.558416,
  -0.550394,
  -0.542426,
  -0.534511,
  -0.526648,
  -0.518835,
  -0.511072,
  -0.503358,
  -0.495691,
  -0.488070,
  -0.480495,
  -0.472965,
  -0.465478,
  -0.458034,
  -0.450631,
  -0.443270,
  -0.435948,
  -0.428665,
  -0.421421,
  -0.414214,
  -0.407043,
  -0.399908,
  -0.392808,
  -0.385743,
  -0.378710,
  -0.371710,
  -0.364743,
  -0.357806,
  -0.350899,
  -0.344023,
  -0.337175,
  -0.330355,
  -0.323563,
  -0.316799,
  -0.310060,
  -0.303347,
  -0.296659,
  -0.289995,
  -0.283354,
  -0.276737,
  -0.270143,
  -0.263570,
  -0.257018,
  -0.250487,
  -0.243976,
  -0.237484,
  -0.231012,
  -0.224558,
  -0.218121,
  -0.211702,
  -0.205299,
  -0.198912,
  -0.192541,
  -0.186185,
  -0.179844,
  -0.173516,
  -0.167202,
  -0.160901,
  -0.154613,
  -0.148336,
  -0.142071,
  -0.135816,
  -0.129572,
  -0.123338,
  -0.117114,
  -0.110898,
  -0.104691,
  -0.098491,
  -0.092300,
  -0.086115,
  -0.079937,
  -0.073764,
  -0.067598,
  -0.061436,
  -0.055280,
  -0.049127,
  -0.042978,
  -0.036832,
  -0.030689,
  -0.024549,
  -0.018410,
  -0.012272,
  -0.006136,
};


// -----------------------------------------------------------------------------
double
ceil(double x)
{
  return ((int32_t)(x+0.5f));
}

// -----------------------------------------------------------------------------
double
cos(double x)
{
  return cosTable[ANGLE_TO_INDEX(x)];
}

// -----------------------------------------------------------------------------
float
cosf(float x)
{
  return cosTable[ANGLE_TO_INDEX(x)];
}

// -----------------------------------------------------------------------------
double
fabs(double x)
{
  return (x >= 0.0f) ? x : -x;
}

// -----------------------------------------------------------------------------
double
floor(double x)
{
  return ((int32_t)x);
}

// -----------------------------------------------------------------------------
double
sin(double x)
{
  return sinTable[ANGLE_TO_INDEX(x)];
}

// -----------------------------------------------------------------------------
float
sinf(float x)
{
  return sinTable[ANGLE_TO_INDEX(x)];
}

// -----------------------------------------------------------------------------
double
tan(double x)
{
  return tanTable[ANGLE_TO_INDEX(x)];
}

// -----------------------------------------------------------------------------
float
tanf(float x)
{
  return tanTable[ANGLE_TO_INDEX(x)];
}

// -----------------------------------------------------------------------------
double
sqrt(double x)
{
  return sqrtf(x);
}

// -----------------------------------------------------------------------------
// From quake
float
sqrtf(float number)
{
  int32_t i;
  float x2 = number * 0.5f;
  float y;

  i = *(int32_t *)&number;
  i = 0x5f3759df - (i >> 1);
  y = *(float *)&i;

  y = y * (1.5f - (x2 * y * y));
  y = y * (1.5f - (x2 * y * y));
  y = y * (1.5f - (x2 * y * y));
  y = y * (1.5f - (x2 * y * y));

  return number*y;
}

// -----------------------------------------------------------------------------
double
inv_sqrt(double x)
{
  return inv_sqrtf(x);
}

// -----------------------------------------------------------------------------
// From quake
float
inv_sqrtf(float number)
{
  int32_t i;
  float x2 = number * 0.5f;
  float y;

  i = *(int32_t *)&number;
  i = 0x5f3759df - (i >> 1);
  y = *(float *)&i;

  y = y * (1.5f - (x2 * y * y));
  y = y * (1.5f - (x2 * y * y));
  y = y * (1.5f - (x2 * y * y));
  y = y * (1.5f - (x2 * y * y));

  return y;
}
